package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("/user")
public class UserController {

    @Autowired
    private UserService userService;


    //@PostMapping
    //@RequestMapping(name = "/save",method = RequestMethod.GET)
    //@GetMapping("/save")
    @PostMapping("/save")
    public boolean save(User user){
        System.out.println(user);
        return userService.save(user);
    }


    @DeleteMapping("/{uuid}")
    public boolean delete(@PathVariable Integer uuid){
        return userService.delete(uuid);
    }


    @PutMapping("/update")
    public boolean update(@RequestBody User user){
        System.out.println("nmsl");
        System.out.println(user);
        return userService.update(user);
    }


    //@GetMapping("/find/{uuid}")
    @GetMapping("/{uuid}")
    public User get(@PathVariable Integer uuid){
        System.out.println(1);
        return userService.get(uuid);
    }


    @GetMapping("/{page}/{size}")
    public PageInfo<User> getAll(@PathVariable Integer page,@PathVariable Integer size){
      return userService.getAll(page,size);

    }


    @PostMapping("/login")
    public  User  login(String userName,String password){
        System.out.println(11);
        return userService.login(userName,password);
    }
}
